package com.dcsgo.socketPlay.server;

import com.dcsgo.socketPlay.common.Message;
import com.dcsgo.socketPlay.server.game.BallManager;

import java.io.IOException;
import java.net.Socket;
import java.util.HashMap;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @author DCSGO
 * @version 1.0
 * 管理Client连接
 */
public class ClientSocketManager {
    private static final ConcurrentHashMap<Integer, Socket> clients = new ConcurrentHashMap<>();

    public static boolean isEmpty() {
        return clients.isEmpty();
    }

    public static void put(Integer clientId, Socket clientSocket) {
        clients.put(clientId, clientSocket);
    }

    public static Socket get(Integer clientId) {
        return clients.get(clientId);
    }

    //端口与客户端的连接
    public static void Disconnect(Integer clientId) throws IOException {
        ServeClientsThreadManager.get(clientId).shutdown();
        ServeClientsThreadManager.remove(clientId);
        BallManager.remove(clientId);
        clients.get(clientId).close();
        clients.remove(clientId);
    }

}
